<template>
  <div class="standard-panel-container full-height">
    <el-tabs v-model="activeName" style="height: 100%;">
      <el-tab-pane label="Standard Detail" name="detail" lazy>
        <standard-detail v-model="standard" :is-edit="true" />
      </el-tab-pane>
      <el-tab-pane label="Item List" name="item-list" lazy>
        <standard-item-list :standard="standard" />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import StandardItemList from '@/views/standard/components/StandardItemList'
import StandardDetail from '@/views/standard/components/StandardDetail'
import { fetchStandard } from '@/api/standard'

export default {
  name: 'StandardPanel',
  components: { StandardDetail, StandardItemList },
  data() {
    return {
      activeName: 'detail',
      standard: null
    }
  },
  watch: {
    '$route'(to, from) {
      if (to.name === 'StandardPanel') {
        this.getTab()
        this.fetchStandard()
      }
    },
    activeName() {
      const router = { name: this.$route.name, query: this.$route.query }
      router.query.tab = this.activeName
    }
  },
  created() {
    this.getTab()
    this.fetchStandard()
  },
  methods: {
    getTab() {
      if (this.$route.query.tab) {
        this.activeName = this.$route.query.tab
      }
    },
    async fetchStandard() {
      const data = await fetchStandard(this.$route.query.id)
      if (data.Message === 'ok') {
        this.standard = data.Data
      }
    }
  }
}
</script>

<style scoped>

</style>
